const fs = require('fs');
const path = require('path');
// fs内容提供了 复制文件的 方法

// async function test() {
//   const fromFilename = path.resolve(__dirname, "./myfiles/1.jpeg");
//   const buffer = await fs.promises.readFile(fromFilename);
//   const toFilename = path.resolve(__dirname, "./myfiles/1.copy.jpeg");
//   await fs.promises.writeFile(toFilename, buffer);
//   console.log("copy success！");
// }

// test();

async function copy() {
  const filename = path.resolve(__dirname, './myfiles/1.jpeg');
  const buffer = await fs.promises.readFile(filename);
  const toFileName = path.resolve(__dirname, './myfiles/copy2.jpeg');
  const result = await fs.promises.writeFile(toFileName, buffer);
  console.log(result, 'result'); // undefined
}

copy();
